/**
 * date:2020/03/01
 * author:wujian
 * version:2.0
 * description:layuimini 统一访问接口
 */
layui.define(['upload'],function (exports) {
    var $ = layui.jquery,
    upload = layui.upload;
    var host = window.location.host;
    var basePath = '/tool/api/v1';
    var myApi = {
        LoginAPI : basePath+'/user/loginCust.do',  // 查询操作
        QueryIdTextAPI : basePath+'/common/queryIdText.do',  // 查询idtext

        ItemQueryAPI : basePath+'/item/query.do',  // 查询事项
        ItemQueryByIdAPI : basePath+'/item/queryById.do',  // 查询事项
        ItemOperateAPI : basePath+'/item/operate.do',  // 查询操作

        DocQueryAPI : basePath+'/doc/query.do',  // 查询文档
        DocOperateAPI : basePath+'/doc/operate.do',  // 查询操作
        HtmlUploadAPI : basePath+'/doc/uploadHtml.do', // 上传文档
        HtmlDownloadAPI : basePath+'/doc/downloadHtml.do', // 上传文档
        DocUploadAPI : basePath+'/doc/upload.do', // 上传日志文件

        DocSpaceQueryAPI : basePath+'/docSpace/query.do',  // 查询文档
        DocSpaceOperateAPI : basePath+'/docSpace/operate.do',  // 查询操作

        LogDetailAPI : basePath+'/log/getLogDetail.do',  // 查询日志明细
        UploadLogAPI : basePath+'/log/uploadLog.do', // 上传日志文件

        IndexDocListAPI : basePath+'/index/queryDocList.do', // 文章列表
        IndexSpaceListAPI : basePath+'/index/querySpaceList.do', // 空间列表

        //请求头
        headers : {},
        getUser : function getUser(){
            var userId = sessionStorage.getItem('userId');
            console.log("userId: " + userId)
            return {userId: userId};
        },
        getHeaders : function getHeaders(){
            var token = sessionStorage.getItem('token');
            console.log("getheaders : " + token)
            return {'token': token};
        },

        get: function (url, param, successCallBackFn, failCallbackFn, options) {
            $.ajax({
                type: "GET",
                url: url,
                data: param,
                success: function (res) {
                    if (successCallBackFn != null && successCallBackFn != undefined) {
                        successCallBackFn(res);
                    }
                },
                error: function (err) {
                    console.log("err", err)
                    if (failCallbackFn != null && failCallbackFn != undefined) {
                        failCallbackFn(res);
                    }else {
                        layer.error(err)
                    }
                }
            });
        },
        postForm: function (url, param, successCallBackFn, failCallbackFn, options) {
            $.ajax({
                type: "POST",
                url: url,
                async: (options==undefined || options.async==undefined)?false:options.async,
                contentType: 'application/x-www-form-urlencoded',
                data: param,
                success: function (res) {
                    if (successCallBackFn != null && successCallBackFn != undefined) {
                        successCallBackFn(res);
                    }
                },
                error: function (err) {
                    console.log("err", err)
                    if (failCallbackFn != null && failCallbackFn != undefined) {
                        failCallbackFn(res);
                    }else {
                        layer.error(err)
                    }
                }
            });
        },
        postJson: function (url, param, successCallBackFn, failCallbackFn, options) {
            $.ajax({
                type: "POST",
                url: url,
                async: (options==undefined || options.async==undefined)?true:options.async,
                contentType: 'application/json',
                // beforeSend: this.before,
                data: JSON.stringify(param),
                success: function (res) {
                    if (successCallBackFn != null && successCallBackFn != undefined) {
                        successCallBackFn(res);
                    }
                },
                error: function (err) {
                    console.log("err", err)
                    if (failCallbackFn != null && failCallbackFn != undefined) {
                        failCallbackFn(res);
                    }else {
                        layer.error(err)
                    }
                }
            });
        },
        uploadFile: function (options) {
            var uploadInst = upload.render(options);
        },
    };

    exports("myApi", myApi);
});